using System.Collections;
using System.Collections.Generic;
using Pinwheel.LSerialize;
using Pinwheel.Toolkits;
using UnityEngine;

[LSerializable]
public partial struct Person
{
    public string Name;
    public int Id;
    public int Age;
    public string Email;
    // public DateTimeOffset Birthday;
    // public Dictionary<int, int> TestDict;
}

[LSerializable]
public partial struct AddressBook
{
    public Person[] Persons;
    public int[] TestInt;
}

public class Sample : MonoBehaviour
{
    public static readonly Person Colo = new Person()
    {
        Name = "Colo",
        Age = 18,
        Id = 1,
        Email = "Colo@163.com",
    };

    public static readonly Person Aliner = new Person()
    {
        Name = "Aliner",
        Age = 16,
        Id = 2,
        Email = "Aliner@163.com"
    };

    public static readonly Person Tom1 = new Person()
    {
        Name = "Tom",
        Age = 60,
        Email = "Tom@163.com",
    };

    public static readonly Person Tom2 = new Person()
    {
        Name = "Tom",
        Age = 61,
        Email = "Tom@163.com",
    };
    
    void Start()
    {
        AddressBook sAddressBook = new AddressBook();
        sAddressBook.Persons = new[]
        {
            Tom1,
            Colo,
            Aliner,
            Tom2,
            Colo,
            Aliner,
            Tom2,
            Tom1
        };
        sAddressBook.TestInt = new[] { 1, 2, 3, 4, 5, 6 };

        AddressBook dAddressBook;

        var bytes = LSerializer.Serialize(ref sAddressBook);
        Debug.Log($"Serialize bytes length->{bytes.Length}");
        dAddressBook = LSerializer.Deserialize<AddressBook>(bytes);
        Debug.Log($"dAddressBook->{dAddressBook}");
        
        Assert.Check(sAddressBook == dAddressBook, "Serialize has error!");
    }
}
